package cn.zjutleo.village_server.controller;



import cn.zjutleo.village_server.entity.UserLogin;
import cn.zjutleo.village_server.mapper.UserLoginMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author: 张坤
 * @DateTime: 2021/8/16 22:50
 * @Description: 该类用于 用户登录
 */
@Api(tags = "用户后台管理系统登录类")
@RestController()
public class UserLoginController {
    @Autowired
    UserLoginMapper userLoginMapper;

    @ApiOperation("账号密码登录")
    @PostMapping("/api/userlogin")
    public UserLogin userLogin(HttpServletRequest request ,@RequestBody UserLogin userLogin){
        System.out.println(userLogin.toString());
        System.out.println("get u_id= "+userLogin.getU_id()+" u_password= "+userLogin.getU_password());
        UserLogin getuser=userLoginMapper.selectByIdPassword(userLogin.getU_id(),userLogin.getU_password());
        if(getuser!=null){
            request.getSession().setAttribute("userLogin",getuser);
            System.out.println(getuser.toString());
            return getuser;
        }else {
            return new UserLogin();
        }
    }
}
